#ifndef GUARD_Map_h
#define GUARD_Map_h

#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_opengl.h>
#include <memory>
#include <fstream>
#include "Collidable.h"

class Map
	{
	private:
		std::auto_ptr<std::vector<std::vector<short> > > worldLayer;
		std::auto_ptr<std::vector<std::vector<short> > > collisionLayer;
		int xSize;
		int ySize;
		float xMax;
		float yMax;
		
		// Map dimensions
		short numRows;
		short numCols;
		
		// Tile info
		short tileHeight;
		short tileWidth;
		short tileSpacing;
		
		// Tileset info
		short numTextures;
		short tileCols;
		short tileRows;
		short tilesetHeight;
		short tilesetWidth;
		short tileMargin;
		
		GLuint texture;
		
		void loadMap(const std::string& mapFileName);
		std::auto_ptr<std::vector<std::vector<short> > > loadLayer(std::ifstream& mapFile);
	public:
		
		Map(const std::string& mapFileName, int xSize, int ySize);
		~Map();
		
		//const std::vector<std::vector<short> >* getData() const;
		
		bool collision(const Collidable& object) const;
		bool outOfBounds(int x, int y) const;
		void draw();
		void update();
		void handleEvent(SDL_Event* event);
		int getViewWidth() const;
		int getViewHeight() const;
		void setMaxBounds(float xMax, float yMax);
	};

#endif

